package com.roy.spring.entity;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by admin on 18-1-13.
 */
@Component
public interface UserRepository extends BaseRepository<User, Long> {

    public List<User> findByUsername(String username);

    //利用原生的SQL进行查询操作
    @Query(value = "select o.* from orders o ,user u where o.uid=u.id and u.name=?1", nativeQuery = true)
    @Modifying
    public List<User> findOrderByName(String name);

    //利用原生的SQL进行修改操作
    @Query(value = "update orders set name=?1 where id=?2 ", nativeQuery = true)
    @Modifying
    public void updateOrderName(String name,int id);
}
